package com.ruoyi.statistics.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.statistics.domain.StockAnalysisVO;
import com.ruoyi.statistics.service.IStockAnalysisService;

/**
 * 库存监控报表Controller
 * 
 * @author ruoyi
 * @date 2025-01-18
 */
@Anonymous
@RestController
@RequestMapping("/statistics/stock")
public class StockAnalysisController extends BaseController
{
    @Autowired
    private IStockAnalysisService stockAnalysisService;

    /**
     * 查询库存监控列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StockAnalysisVO stockAnalysisVO)
    {
        startPage();
        // 添加组织过滤
        stockAnalysisVO.setOrgId(getDeptId());
        List<StockAnalysisVO> list = stockAnalysisService.selectStockAnalysisList(stockAnalysisVO);
        return getDataTable(list);
    }

    /**
     * 获取库存健康度统计
     */
    @GetMapping("/statistics")
    public AjaxResult getStatistics(StockAnalysisVO stockAnalysisVO)
    {
        // 添加组织过滤
        stockAnalysisVO.setOrgId(getDeptId());
        Map<String, Object> statistics = stockAnalysisService.getStockStatistics(stockAnalysisVO);
        return success(statistics);
    }

    /**
     * 获取库存变动趋势
     */
    @GetMapping("/trend")
    public AjaxResult getStockTrend(StockAnalysisVO stockAnalysisVO)
    {
        // 添加组织过滤
        stockAnalysisVO.setOrgId(getDeptId());
        List<Map<String, Object>> trend = stockAnalysisService.getStockTrend(stockAnalysisVO);
        return success(trend);
    }

    /**
     * 获取预警商品列表
     */
    @GetMapping("/warning")
    public TableDataInfo getWarningProducts(StockAnalysisVO stockAnalysisVO)
    {
        // 添加组织过滤
        stockAnalysisVO.setOrgId(getDeptId());
        startPage();
        List<StockAnalysisVO> warningList = stockAnalysisService.getWarningProducts(stockAnalysisVO);
        return getDataTable(warningList);
    }

    /**
     * 导出库存监控列表
     */
    @Log(title = "库存监控", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(HttpServletResponse response, StockAnalysisVO stockAnalysisVO)
    {
        // 添加组织过滤
        stockAnalysisVO.setOrgId(getDeptId());
        List<StockAnalysisVO> list = stockAnalysisService.selectStockAnalysisList(stockAnalysisVO);
        ExcelUtil<StockAnalysisVO> util = new ExcelUtil<StockAnalysisVO>(StockAnalysisVO.class);
        util.exportExcel(response, list, "库存监控数据");
    }
}